<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	</head>
	<body>
		<div class="right-sidebar" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
		        <li role="presentation" class="active"><a href="withdraw.html">提现申请</a></li>
		        <li role="presentation"><a href="withdrawList.html">提现记录</a></li>
		    </ul>
		
		    <empty name='is_withdraw'>
		        <div class="alert alert-warning" role="alert">对不起，当前剩余可提现余额为 {$wait_withdraw}元，没有达到提现目标金额（{$rules.agent_withdraw_least}元），暂不可提现！</div>
		        <else/>
		
		        <div class="alert alert-info" role="alert">
		            <p>可提现金额：<strong id="wait">{$wait_withdraw}</strong>&nbsp;元</p>
		            <p>提交后请联系管理员给您支付！</p>
		        </div>
		
		        <div>
		            <div class="form-group">
		                <label for="amount" class="col-sm-4 control-label">提现金额</label>
		                <div class="col-sm-8">
		                    <input type="number" min="0" class="form-control" name="amount" id="amount">
		                    <div class="alert alert-danger hide" role="alert" id="amount-tips"></div>
		                </div>
		            </div>
		            <button type="button" class="btn btn-primary center-block" id="submit" data-toggle="modal" data-target="#myModal">申请</button>
		        </div>
		    </empty>
		    
		    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
			  <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="exampleModalLabel">请选择提现方式</h4>
			      </div>
			      <div class="modal-body">
			        <div class="row">
						<div class="col-md-12">
							<div class="input-group">
				                <span class="input-group-addon">申请人&emsp;</span>
				                <input type="text" class="form-control" name="user_id" id="user_id" disabled="true" value="{$user_id}">
				            </div>
				            <div class="input-group" id="payment">
				                <span class="input-group-addon">提现方式</span>
				                <div class="form-control" >
									<input type="radio"  name="payment" value="1" id="payment1">支付宝
									<input type="radio"  name="payment" value="2" id="payment2">微信
									<input type="radio"  name="payment" value="3" id="payment3" checked="checked">银行卡
								</div>
				            </div>
							
							<div id="box1" style="display: none;">
								<div class="input-group">
									<span class="input-group-addon">真实姓名</span>
									<input type="text" class="form-control" name="name" id="name" value="{$user.name}" disabled="disabled">
								</div>
					            <div class="input-group">
					                <span class="input-group-addon">支付宝号</span>
					                <input type="text" class="form-control" name="pay_num" id="pay_num" value="{$user.pay_num}" >
					            </div>
							</div>
							<div id="box2" style="display: none;">
								<div class="input-group">
									<span class="input-group-addon">真实姓名</span>
									<input type="text" class="form-control" name="name" id="name" value="{$user.name}" disabled="disabled">
								</div>
					            <div class="input-group">
					                <span class="input-group-addon">微信号&emsp;</span>
					                <input type="text" class="form-control" name="wchat" id="wchat" value="{$user.wchat}" >
					            </div>
							</div>
							<div id="box3" style="display: none;">
								<div class="input-group">
									<span class="input-group-addon">真实姓名</span>
									<input type="text" class="form-control" name="name" id="name1" value="{$user.name}" disabled="disabled">
								</div>
								<div class="input-group">
									<span class="input-group-addon">开户银行</span>
									<input type="text" class="form-control" name="bank_name" id="bank_name" value="{$user.bank_name}" >
								</div>
					            <div class="input-group">
					                <span class="input-group-addon">银行账号</span>
					                <input type="text" class="form-control" name="bank_card" id="bank_card" value="{$user.bank_card}" >
					            </div>
							</div>
						</div>
					</div>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-primary" id="sbtn">提交</button>
			      </div>
			    </div>
			  </div>
			</div>
		</div>
		<script type="text/javascript">
			$(function(){
				getStyle();
				$("#payment input").on("click",function(){
					getStyle();
				});
				
				$("#amount").blur(function(){
					var withdraw = $.trim($('#amount').val());
					var wait_withdraw=parseInt($("#wait").text());
					if(withdraw == '' || parseInt(withdraw) <= 0) {
						alert("请注意提现的金额！");
						window.location.href="{:U('Admin/Main/withdraw')}";
						return false;
					}
					
					if(parseInt(withdraw) > wait_withdraw) {
						alert("提现金额不能大于待提现金额！");
						window.location.href="{:U('Admin/Main/withdraw')}";
						return false;
					}
				});
			});
		
			function getStyle(){
				var payment = $("#payment input[name='payment']:checked").val();
					if(parseInt(payment) == 1) {
						$("#box1").show();
						$("#box2,#box3").hide();
					}else if(parseInt(payment) == 2) {
						$("#box2").show();
						$("#box1,#box3").hide();
					}else if(parseInt(payment) == 3) {
						$("#box3").show();
						$("#box1,#box2").hide();
					}
			}
			
			$("#sbtn").on("click",function(){
				var withdraw = $.trim($('#amount').val());
				var wait_withdraw=parseInt($("#wait").text());
				if(withdraw == '' || parseInt(withdraw) <= 0) {
					alert("请注意提现的金额！");
					window.location.href="{:U('Admin/Main/withdraw')}";
					return false;
				}
				
				if(parseInt(withdraw) > wait_withdraw) {
					alert("提现金额不能大于待提现金额！");
					window.location.href="{:U('Admin/Main/withdraw')}";
					return false;
				}
				var withdraw = $.trim($('#amount').val()); 
				var name = $.trim($('#name1').val());
				var payment = $("#payment input[name='payment']:checked").val(); 
				var bank_name = $.trim($('#bank_name').val()); 
				var bank_card = $.trim($('#bank_card').val()); 
				var pay_num =  $.trim($('#pay_num').val());
				var wchat =  $.trim($('#wchat').val());
				var data = '';
				if(parseInt(payment) == 1) {
					data = {'payment':payment,'payment_no':pay_num,'withdraw':withdraw,'name':name};
				}else if(parseInt(payment) == 2) {
					data = {'payment':payment,'payment_no':wchat,'withdraw':withdraw,'name':name};
				}else if(parseInt(payment) == 3) {
					data = {'payment':payment,'payment_no':bank_card,'withdraw':withdraw,'name':name,'bank_name':bank_name};
				}
				console.log(data);
				$.ajax({
					type:"post",
					url:"{:U('Admin/Main/withdrawSave')}",
					dataType:"json",
					data:data,
					success:function(data) {
						console.log(data);
						if(data == 'success') {
							alert("申请成功，等待审核！");
							window.location.href="{:U('Admin/Main/withdraw')}";
						}else if(data == 'nbank_card'){
							alert("银行卡号不能为空！");
						}else if(data == 'npay_num') {
							alert('支付宝账号不能为空');
						}else if(data == 'nwchat') {
							alert('微信号不能为空！');
						}else if(data == 'error') {
							alert('申请失败！');
							window.location.href="{:U('Admin/Main/withdraw')}";
						}
					}
				});
				
			});
		
		
		
//			$("#submit").on("click",function(){
//				var payment = 3;
//				var payment_no = '';
//				var withdraw = $.trim($('#amount').val());
//				var wait_withdraw=parseInt($("#wait").text());
//				if(withdraw == '' || parseInt(withdraw) <= 0) {
//					alert("请注意提现的金额！");
//					return false;
//				}
//				
//				if(parseInt(withdraw) > wait_withdraw) {
//					alert("提现金额不能大于待提现金额！");
//					window.location.href="{:U('Admin/Main/withdraw')}";
//					return false;
//				}
//				
//				var url="{:U('Admin/Main/withdrawSave')}";
//				$.ajax({
//					type:"post",
//					url:url,
//					dataType:"json",
//					data:{'payment':payment,'payment_no':payment_no,'withdraw':withdraw},
//					success:function(data) {
////						console.log(data);
//						if(data == 'success') {
//							alert("申请成功，等待审核！");
//							window.location.href="{:U('Admin/Main/withdraw')}";
//						}else if(data == 'error'){
//							alert("申请失败！");
//						}
//					}
//				});
//			});
		</script>
	</body>
</html>
